Skip to content

Snap scenery objects vertex-to-vertex and edge-to-edge - #123

Merged
turbo-devv merged 8 commits into
openOMSI-org:mainfrom
benchan0527:feat/vertex-snap
Nov 14, 2026
Merged

turbo-devv merged 8 commits into
openOMSI-org:mainfrom
benchan0527:feat/vertex-snap

Conversation

@benchan0527

Copy link
Copy Markdown
Contributor

Summary

  • Vertex-to-vertex snapping (Key V): Allows snapping a scenery object to another object by matching a selected vertex from the source object to a target vertex on another object, translating the whole source object accurately.
  • Edge-to-edge snapping (Key L): Allows aligning and snapping a scenery object along an edge of another object or along a road/spline:
    • Supports full 3D rotation alignment or horizontal-only yaw alignment (Shift key).
    • Works with mesh edges (including complex models up to 200,000 edges) and object bounding box edges.
    • Supports snapping to road splines as target edges.
  • UI & Controls:
    • Added dedicated snap buttons in the top toolbar and in the right-side Scenery Object properties panel.
    • Interactive visual overlay: shows highlighted glowing vertices and edge lines, depth-culled nearest raycast picking, and a connecting guide line while picking.
    • Registered in Command Palette (Ctrl+P -> "Snap Vertex to Vertex", "Snap Edge to Edge").
    • Mutually exclusive activation between vertex snap and edge snap modes.
  • Asset path normalization: Normalized backslashes and slashes in asset lookup keys so models located in subfolders load reliably on all platforms.

Test plan

  • Select a scenery object, press V (or click the vertex snap button in toolbar/properties panel): glowing red vertices appear. Click a vertex on the source object, then click a target vertex on another object; confirm the source object snaps cleanly to align the two vertices.
  • Select a scenery object, press L (or click the edge snap button): orange wireframe edges appear. Click a source edge, then click a target edge on another object or road spline; confirm the source object rotates and translates to align along the target edge.
  • Hold Shift while clicking a target edge in edge snap mode; confirm rotation is constrained to horizontal yaw only.
  • Test on a large complex scenery object (e.g. northkcnewnew2.sco with >30k edges); confirm all edges render and are selectable without crashing or freezing.
  • Press Esc at any time during snapping to cancel cleanly without altering the scene.
  • Run cargo test --bin openmapper snap; confirm all unit tests pass.

@turbo-devv
turbo-devv merged commit 12d352e into openOMSI-org:main Nov 14, 2026
4 checks passed

@turbo-devv turbo-devv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a useful feature, but a few things need to change before it can go in:

  1. It takes over V and L. The new KeyCode::KeyV / KeyCode::KeyL branches in App run before the keymap, whenever the crossing editor is closed. In openMapper's own key set V is XformMove and L is Lines (src/controls.rs), so both stop working, even with nothing selected: you only get the "Select an object first" toast. The new modes need commands in controls.rs (with free default keys, rebindable like the others), not hardcoded keys.
  2. CONTRIBUTING: new code goes into new files. Around 1,200 lines go into src/editor.rs, which should only get small hooks. Please move the snap state, picking, apply and overlay code into its own module (e.g. src/snap.rs) and keep only the calls in editor.rs / app.rs / ui.rs.
  3. Cost on every mouse move and frame. vertex_at_ray / edge_at_ray run on every hover_ray. In target mode they go through every tile without a tile cull and rebuild object_vertices_for_snap / object_edges_for_snap (new HashSets, up to 200,000 edges) for every object within 600 m. They also sample every spline on the map every 8 m with no distance check. The overlay pushes up to 200,000 edge lines and all deduplicated vertices of the selection every frame. Please cull tiles and splines by distance as lanes::near_skipping does, cache the selected objects' vertices/edges for the duration of the mode, and cap what goes into the overlay.
  4. Bug in edge_at_ray. The continue in the centre-line occlusion check skips that segment's curb edges too.
  5. The same hit/score block is repeated about eight times. One helper would make it shorter and easier to check.

The assets.rs key normalisation is fine on its own, but it is a separate change and would be better as a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants